﻿/*****************************************************************************  

 Version: 0.1
 Website: http://www.visuagile.com/
 
 Copyright (c) Yoganand R. All rights reserved.
 For continued development and updates, visit http://yogsbreath.net
 
 ******************************************************************************/

using System;
using System.Collections;
using System.Collections.Generic;
using NHibernate;
using Spring.Data.NHibernate.Support;

using VisualAgile.IDAL;
using VisualAgile.Model;
using Spring.Data.NHibernate;
using NHibernate.Engine;

namespace VisualAgile.DAL
{
    public abstract class BaseDao<EntityT> : HibernateDaoSupport, IBaseDao<EntityT>
    {
        protected abstract HibernateTemplate getBaseDAO();

        public virtual EntityT Save(EntityT entity)
        {
            this.getBaseDAO().Save(entity);
            return entity;
        }

        public virtual EntityT SaveOrUpdate(EntityT entity)
        {
            this.getBaseDAO().SaveOrUpdate(entity);
            return entity;
        }
        public virtual void Delete(EntityT entity)
        {
            this.getBaseDAO().Delete(entity);
        }

        public virtual EntityT FindById(Guid entityId)
        {
            return (EntityT)this.getBaseDAO().Get(typeof(EntityT), entityId);
        }

        public virtual IList FindAll()
        {
            return this.getBaseDAO().LoadAll(typeof(EntityT));
        }
    }

}
